<?php
$id = Zend_Controller_Front::getInstance()->getRequest()->getParam('id');

$peers = BlogCommentPeer::getInstance();
$select = $peers->select()->where('id = ?', $id);
$comment = $peers->fetchRow($select);
if (!$comment) $comment = BlogCommentPeer::getInstance()->createRow();

$message = BlogMessagePeer::getInstance();
$select = $message->select()->where('id = ?', $comment['item_id']);
$result_m = $message->fetchRow($select);

$form = $this->element;
?>

<link rel="stylesheet" media="screen" href="http://<?php echo Config::getInstance()->default->hostname; ?>/style/admin_product.css" />
<!--[if lte IE 7]><link href="/style/ie.css" rel="stylesheet" type="text/css"><![endif]-->
<form enctype="multipart/form-data" method="post" action="">

	<h2 style="color:#4b0082;">Комментарий к теме ID=<?php echo $result_m['id']; ?> "<?php echo $result_m['title']; ?>"</h2>
  <div>
    <?php
    /**
     * Translate some form errrors.
     *
     * @param string $key
     * @param string $error
     * @return string
     */
    function _translate($key, $error)
    {
    	$_translated = array(
			'isEmpty' => 'Поле обязательно для заполнения',
		);
	
    	if (isset($_translated[$key])) {
    		return $_translated[$key];
    	}
    	
    	return $error;
    }
    $errors = $form->getMessages();
    foreach ($errors as $key => $error) {
    	if (is_array($error)) {
    		unset($errors[$key]);
    	}

   		if (is_array($error)) {
     		foreach ($error as $k => $v) {
     			$label = $form->getElement($key)->getLabel();
     			$v = _translate($k, $v);
     			$errors[$key][$k] = "$label -- $v";
     		}
    	} else {
    		$errors[$key] = _translate($key, $error);
    	}
    }
    
    if ($errors) {
	    echo "<ul class='errors'>";
	    foreach ($errors as $error) {
	    	if (is_array($error)) {
	    		foreach ($error as $k => $v) {
	    			echo "<li>$v</li>";
	    		}
	    	} else {
	    		echo "<li>$error</li>";
	    	}
	    }
	    echo "</ul>";
    }
    ?>
	<?php
		$title = $form->getElement('title');
		echo $title;
	?>
	<br>
    <?php echo $form->getElement('text'); ?>
	<br>
	<?php
		  $datas = $form->getElement('created_at');
		  $datas->setAttrib('readonly', 'readonly');
		  $datas->setAttrib('style', 'background-color: #EEE;');
		  if(!$comment['created_at']){
			  $datas->setValue(date('Y-m-d H:i:s'));
		    }
		  echo $datas;
    ?>
	<br>
   <dd id="submit-element">
        <input type="submit" name="submit" id="submit" value="Сохранить">
	   <?php echo $form->getElement('crud_exit'); ?>
   </dd>
  </div>
</form>